added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / jsclosurefield.cs
blob3ab817bdc7a925f50bc543be8b71bc5f571b8bb7
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 namespace Microsoft.JScript {
18 using System;
19 using System.Globalization;
20 using System.Reflection;
22 internal sealed class JSClosureField : JSVariableField{
23 internal FieldInfo field; //Used to indicate that the field is accessed from a nested (static) function.
25 internal JSClosureField(FieldInfo field)
26 : base(field.Name, null, field.Attributes|FieldAttributes.Static){ //Fool the analysis code to OK calls to this method from static code
27 if (field is JSFieldInfo) field = ((JSFieldInfo)field).field;
28 this.field = field;
31 public override Type DeclaringType{
32 get{
33 return this.field.DeclaringType;
37 public override Type FieldType{
38 get{
39 return this.field.FieldType;
43 internal override IReflect GetInferredType(JSField inference_target){
44 if (this.field is JSMemberField)
45 return ((JSMemberField)this.field).GetInferredType(inference_target);
46 else
47 return this.field.FieldType;
50 internal override Object GetMetaData(){
51 if (this.field is JSField)
52 return ((JSField)this.field).GetMetaData();
53 else
54 return this.field;
57 public override Object GetValue(Object obj){
58 if (obj is StackFrame)
59 return this.field.GetValue(((StackFrame)((StackFrame)obj).engine.ScriptObjectStackTop()).closureInstance);
60 throw new JScriptException(JSError.InternalError); //should never happen
63 public override void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo locale){
64 if (obj is StackFrame){
65 this.field.SetValue(((StackFrame)((StackFrame)obj).engine.ScriptObjectStackTop()).closureInstance, value, invokeAttr, binder, locale);
66 return;
68 throw new JScriptException(JSError.InternalError); //should never happen